
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.6.1 proto使用之文件创建 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="162-protoshi-yong-zhi-du-xie-cao-zuo.html" />
    
    
    <link rel="prev" href="../16-ben-zhang-xiao-jie.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../../chapter1.html">
            
                <a href="../../chapter1.html">
            
                    
                    第1章 Cyber RT 概述与环境搭建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../11-cyber-rt-jian-jie.html">
            
                <a href="../11-cyber-rt-jian-jie.html">
            
                    
                    1.1 Cyber RT 简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../12-cyber-rt-an-zhuang.html">
            
                <a href="../12-cyber-rt-an-zhuang.html">
            
                    
                    1.2 Cyber RT 安装
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../12-cyber-rt-an-zhuang/121-zhun-bei-gong-zuo.html">
            
                <a href="../12-cyber-rt-an-zhuang/121-zhun-bei-gong-zuo.html">
            
                    
                    1.2.1 准备工作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="../12-cyber-rt-an-zhuang/122-cyber-rt-an-zhuang.html">
            
                <a href="../12-cyber-rt-an-zhuang/122-cyber-rt-an-zhuang.html">
            
                    
                    1.2.2 Cyber RT 安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="../12-cyber-rt-an-zhuang/123-ce-shi.html">
            
                <a href="../12-cyber-rt-an-zhuang/123-ce-shi.html">
            
                    
                    1.2.3 测试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian.html">
            
                <a href="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian.html">
            
                    
                    1.3 Cyber RT 集成开发环境搭建
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.3.1" data-path="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian/131-vscode-xia-zai-yu-an-zhuang.html">
            
                <a href="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian/131-vscode-xia-zai-yu-an-zhuang.html">
            
                    
                    1.3.1 Vscode 下载与安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3.2" data-path="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian/132-vscode-cha-jian-de-an-zhuang-yi-ji-shi-yong.html">
            
                <a href="../14-cyber-rt-ji-cheng-kai-fa-huan-jing-da-jian/132-vscode-cha-jian-de-an-zhuang-yi-ji-shi-yong.html">
            
                    
                    1.3.2 Vscode 插件的安装以及使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../13-cyber-rt-kuai-su-ti-yan.html">
            
                <a href="../13-cyber-rt-kuai-su-ti-yan.html">
            
                    
                    1.4 Cyber RT 快速体验
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.4.1" data-path="../13-cyber-rt-kuai-su-ti-yan/141-cshi-xian-helloworld.html">
            
                <a href="../13-cyber-rt-kuai-su-ti-yan/141-cshi-xian-helloworld.html">
            
                    
                    1.4.1 c++实现HelloWorld
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4.2" data-path="../13-cyber-rt-kuai-su-ti-yan/142-pythonshi-xian-helloworld.html">
            
                <a href="../13-cyber-rt-kuai-su-ti-yan/142-pythonshi-xian-helloworld.html">
            
                    
                    1.4.2 Python实现HelloWorld
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../15-zhun-bei-1-bazel.html">
            
                <a href="../15-zhun-bei-1-bazel.html">
            
                    
                    1.5 预备知识——bazel
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.5.1" data-path="../15-zhun-bei-1-bazel/151-bazel-ji-ben-shi-yong-liu-cheng.html">
            
                <a href="../15-zhun-bei-1-bazel/151-bazel-ji-ben-shi-yong-liu-cheng.html">
            
                    
                    1.5.1 Bazel使用之基本流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5.2" data-path="../15-zhun-bei-1-bazel/151-bazel.html">
            
                <a href="../15-zhun-bei-1-bazel/151-bazel.html">
            
                    
                    1.5.2 Bazel使用之库依赖
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../16-ben-zhang-xiao-jie.html">
            
                <a href="../16-ben-zhang-xiao-jie.html">
            
                    
                    1.6 预备知识——protobuf
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.2.6.1" data-path="161-protoshi-yong-zhi-wen-jian-chuang-jian.html">
            
                <a href="161-protoshi-yong-zhi-wen-jian-chuang-jian.html">
            
                    
                    1.6.1 proto使用之文件创建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6.2" data-path="162-protoshi-yong-zhi-du-xie-cao-zuo.html">
            
                <a href="162-protoshi-yong-zhi-du-xie-cao-zuo.html">
            
                    
                    1.6.2 proto读写之C++实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6.3" data-path="163-protodu-xie-zhi-python-shi-xian.html">
            
                <a href="163-protodu-xie-zhi-python-shi-xian.html">
            
                    
                    1.6.3 proto读写之Python实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../17-ben-zhang-xiao-jie.html">
            
                <a href="../17-ben-zhang-xiao-jie.html">
            
                    
                    1.7 本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi.html">
            
                    
                    第2章 Cyber RT 通信机制
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin.html">
            
                    
                    2.1 话题通信
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin/211cshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin/211cshi-xian.html">
            
                    
                    2.1.1C++实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin/212-pythonshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/21-hua-ti-tong-xin/212-pythonshi-xian.html">
            
                    
                    2.1.2 Python实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin.html">
            
                    
                    2.2 服务通信
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.2.1" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin/221-cshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin/221-cshi-xian.html">
            
                    
                    2.2.1 C++实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin/222-pythonshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/22-fu-wu-tong-xin/222-pythonshi-xian.html">
            
                    
                    2.2.2 Python实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu.html">
            
                    
                    2.3 参数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.3.1" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu/231-cshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu/231-cshi-xian.html">
            
                    
                    2.3.1 C++实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu/232-pythonshi-xian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/23-can-shu/232-pythonshi-xian.html">
            
                    
                    2.3.2 Python实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian.html">
            
                    
                    2.4 组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.4.1" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/241-ji-ben-component-yan-shi.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/241-ji-ben-component-yan-shi.html">
            
                    
                    2.4.1 通用组件演示(上)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/242-ji-ben-zu-jian-yan-793a28-4e0b29.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/242-ji-ben-zu-jian-yan-793a28-4e0b29.html">
            
                    
                    2.4.2 通用组件演示(下)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4.3" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/242-shi-jian-zu-jian-yan-shi.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/24-zu-jian/242-shi-jian-zu-jian-yan-shi.html">
            
                    
                    2.4.3 定时器组件演示
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/25-ben-zhang-xiao-jie.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/25-ben-zhang-xiao-jie.html">
            
                    
                    2.5 本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../../di-3-zhang-cyber-rt-kai-fa-gong-ju.html">
            
                <a href="../../di-3-zhang-cyber-rt-kai-fa-gong-ju.html">
            
                    
                    第3章 Cyber RT 开发工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder.html">
            
                <a href="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder.html">
            
                    
                    3.1 cyber record
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder/321-c++-shi-xian.html">
            
                <a href="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder/321-c++-shi-xian.html">
            
                    
                    3.2.1 C++ 实现
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder/332-python-shi-xian.html">
            
                <a href="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/32-cyberrecorder/332-python-shi-xian.html">
            
                    
                    3.3.2 Python 实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/25-chang-yong-ming-ling.html">
            
                <a href="../../di-2-zhang-cyber-rt-tong-xin-ji-zhi/25-chang-yong-ming-ling.html">
            
                    
                    3.2 常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/33-ben-zhang-xiao-jie.html">
            
                <a href="../../di-3-zhang-cyber-rt-kai-fa-gong-ju/33-ben-zhang-xiao-jie.html">
            
                    
                    3.3 本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../zi-65993a-chang-yong-api.html">
            
                <a href="../../zi-65993a-chang-yong-api.html">
            
                    
                    第4章 Cyber RT 常用API
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../zi-65993a-chang-yong-api/1apiwen-dang.html">
            
                <a href="../../zi-65993a-chang-yong-api/1apiwen-dang.html">
            
                    
                    4.1 节点相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../zi-65993a-chang-yong-api/2shi-jian-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/2shi-jian-xiang-guan-api.html">
            
                    
                    4.2 话题相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../../zi-65993a-chang-yong-api/3ding-shi-qi-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/3ding-shi-qi-xiang-guan-api.html">
            
                    
                    4.3 服务相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../../zi-65993a-chang-yong-api/44-can-shu-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/44-can-shu-xiang-guan-api.html">
            
                    
                    4.4 参数相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../../zi-65993a-chang-yong-api/45-zu-jian-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/45-zu-jian-xiang-guan-api.html">
            
                    
                    4.5 组件相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../../zi-65993a-chang-yong-api/46-shi-jian-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/46-shi-jian-xiang-guan-api.html">
            
                    
                    4.6 时间相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../../zi-65993a-chang-yong-api/47-ri-zhi-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/47-ri-zhi-xiang-guan-api.html">
            
                    
                    4.7 日志相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../../zi-65993a-chang-yong-api/48-record-xiang-guan-api.html">
            
                <a href="../../zi-65993a-chang-yong-api/48-record-xiang-guan-api.html">
            
                    
                    4.8 record 相关API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../../zi-65993a-chang-yong-api/48-ben-zhang-xiao-jie.html">
            
                <a href="../../zi-65993a-chang-yong-api/48-ben-zhang-xiao-jie.html">
            
                    
                    4.9 本章小结
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >1.6.1 proto使用之文件创建</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h3 id="161-proto&#x4F7F;&#x7528;&#x4E4B;&#x6587;&#x4EF6;&#x521B;&#x5EFA;">1.6.1 proto&#x4F7F;&#x7528;&#x4E4B;&#x6587;&#x4EF6;&#x521B;&#x5EFA;</h3>
<p>&#x672C;&#x8282;&#x4F1A;&#x4ECB;&#x7ECD;&#x5982;&#x4F55;&#x521B;&#x5EFA; proto &#x6587;&#x4EF6;&#x5E76;&#x751F;&#x6210;&#x53EF;&#x88AB; C++ &#x548C; Python &#x76F4;&#x63A5;&#x8C03;&#x7528;&#x7684;&#x6E90;&#x7801;&#x6587;&#x4EF6;&#x3002;</p>
<h4 id="1-&#x521B;&#x5EFA;-proto-&#x6587;&#x4EF6;">1. &#x521B;&#x5EFA; proto &#x6587;&#x4EF6;</h4>
<p>&#x5728; /apollo/cyber &#x76EE;&#x5F55;&#x4E0B;&#x65B0;&#x5EFA;&#x6587;&#x4EF6;&#x5939; demo_base_proto&#xFF0C;&#x6587;&#x4EF6;&#x5939;&#x4E0B;&#x65B0;&#x5EFA;&#x6587;&#x4EF6; student.proto&#xFF0C;&#x5E76;&#x8F93;&#x5165;&#x5982;&#x4E0B;&#x5185;&#x5BB9;&#xFF1A;</p>
<pre><code class="lang-cpp"><span class="hljs-comment">// &#x4F7F;&#x7528;&#x7684; proto &#x7248;&#x672C;, Cyber RT &#x4E2D;&#x76EE;&#x524D;&#x4F7F;&#x7528;&#x7684;&#x662F; proto2</span>
syntax = <span class="hljs-string">&quot;proto2&quot;</span>;
<span class="hljs-comment">//&#x5305;</span>
package apollo.cyber.demo_base_proto;

<span class="hljs-comment">//&#x6D88;&#x606F; --- message &#x662F;&#x5173;&#x952E;&#x5B57;&#xFF0C;Student &#x6D88;&#x606F;&#x540D;&#x79F0;</span>
message Student {
    <span class="hljs-comment">//&#x5B57;&#x6BB5;</span>
    <span class="hljs-comment">//&#x5B57;&#x6BB5;&#x683C;&#x5F0F;: &#x5B57;&#x6BB5;&#x89C4;&#x5219; &#x6570;&#x636E;&#x7C7B;&#x578B; &#x5B57;&#x6BB5;&#x540D;&#x79F0; &#x5B57;&#x6BB5;&#x7F16;&#x53F7;</span>
    required <span class="hljs-built_in">string</span> name = <span class="hljs-number">1</span>;
    optional uint64 age = <span class="hljs-number">2</span>;
    optional <span class="hljs-keyword">double</span> height = <span class="hljs-number">3</span>;
    repeated <span class="hljs-built_in">string</span> books = <span class="hljs-number">4</span>;
}
</code></pre>
<p><strong>proto &#x4E2D;&#x7684;&#x5B57;&#x6BB5;&#x8BED;&#x6CD5;&#xFF0C;</strong>&#x5B57;&#x6BB5;&#x5C31;&#x683C;&#x5F0F;&#x800C;&#x8A00;&#x4E3B;&#x8981;&#x6709;&#x56DB;&#x90E8;&#x5206;&#x7EC4;&#x6210;&#xFF1A;<strong>&#x5B57;&#x6BB5;&#x89C4;&#x5219;</strong>&#x3001;<strong>&#x6570;&#x636E;&#x7C7B;&#x578B;</strong>&#x3001;<strong>&#x5B57;&#x6BB5;&#x540D;&#x79F0;</strong>&#x3001;<strong>&#x5B57;&#x6BB5;&#x7F16;&#x53F7;</strong>&#xFF0C;&#x63A5;&#x4E0B;&#x6765;&#x5206;&#x522B;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x8FD9;&#x56DB;&#x79CD;&#x683C;&#x5F0F;&#x3002;</p>
<h5 id="1&#x5B57;&#x6BB5;&#x89C4;&#x5219;">1.&#x5B57;&#x6BB5;&#x89C4;&#x5219;</h5>
<p>&#x5B57;&#x6BB5;&#x7C7B;&#x578B;&#x4E3B;&#x8981;&#x6709;&#x5982;&#x4E0B;&#x4E09;&#x79CD;&#xFF1A;</p>
<ul>
<li><p>required &#x2014;&#x2014; &#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x5FC5;&#x987B;&#x63D0;&#x4F9B;&#x8BE5;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#xFF0C;&#x5426;&#x5219;&#x8BE5;&#x6D88;&#x606F;&#x5C06;&#x88AB;&#x89C6;&#x4E3A;&#x201C;&#x672A;&#x521D;&#x59CB;&#x5316;&#x201D;&#xFF0C;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x5F53;&#x9700;&#x8981;&#x628A;&#x5B57;&#x6BB5;&#x4FEE;&#x6539;&#x4E3A;&#x5176;&#x4ED6;&#x89C4;&#x5219;&#x65F6;&#xFF0C;&#x4F1A;&#x5B58;&#x5728;&#x517C;&#x5BB9;&#x6027;&#x95EE;&#x9898;&#x3002;</p>
</li>
<li><p>optional &#x2014;&#x2014; &#x8C03;&#x7528;&#x65F6;&#x8BE5;&#x5B57;&#x6BB5;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x4E5F;&#x53EF;&#x4EE5;&#x4E0D;&#x8BBE;&#x7F6E;&#xFF0C;&#x4E0D;&#x8BBE;&#x7F6E;&#x65F6;&#xFF0C;&#x4F1A;&#x6839;&#x636E;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x751F;&#x6210;&#x9ED8;&#x8BA4;&#x503C;&#x3002;</p>
</li>
<li><p>repeated &#x2014;&#x2014; &#x8BE5;&#x89C4;&#x5219;&#x5B57;&#x6BB5;&#x53EF;&#x4EE5;&#x4EE5;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x5F0F;&#x5B58;&#x50A8;&#x591A;&#x4E2A;&#x6570;&#x636E;&#x3002;</p>
</li>
</ul>
<h5 id="2&#x6570;&#x636E;&#x7C7B;&#x578B;">2.&#x6570;&#x636E;&#x7C7B;&#x578B;</h5>
<p>protobuf &#x4E2D;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0E;&#x4E0D;&#x540C;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x5B58;&#x5728;&#x4E00;&#x5B9A;&#x7684;&#x6620;&#x5C04;&#x5173;&#x7CFB;&#xFF0C;&#x5177;&#x4F53;&#x53EF;&#x53C2;&#x8003;&#x5B98;&#x65B9;&#x8D44;&#x6599;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="../../assets/013_protobuf&#x6570;&#x636E;&#x7C7B;&#x578B;.png" alt=""></p>
<h5 id="3&#x5B57;&#x6BB5;&#x540D;&#x79F0;">3.&#x5B57;&#x6BB5;&#x540D;&#x79F0;</h5>
<p>&#x5B57;&#x6BB5;&#x540D;&#x79F0;&#x5C31;&#x662F;&#x53D8;&#x91CF;&#x540D;&#xFF0C;&#x5176;&#x547D;&#x540D;&#x89C4;&#x5219;&#x53C2;&#x8003;C++&#x4E2D;&#x7684;&#x53D8;&#x91CF;&#x540D;&#x547D;&#x540D;&#x89C4;&#x5219;&#x5373;&#x53EF;&#x3002;</p>
<h5 id="4&#x5B57;&#x6BB5;&#x7F16;&#x53F7;">4.&#x5B57;&#x6BB5;&#x7F16;&#x53F7;</h5>
<p>&#x6BCF;&#x4E2A;&#x5B57;&#x6BB5;&#x90FD;&#x6709;&#x4E00;&#x4E2A;&#x552F;&#x4E00;&#x7F16;&#x53F7;&#xFF0C;&#x7528;&#x4E8E;&#x5728;&#x6D88;&#x606F;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x683C;&#x5F0F;&#x4E2D;&#x6807;&#x8BC6;&#x5B57;&#x6BB5;&#x3002;</p>
<h4 id="2-proto&#x6587;&#x4EF6;&#x7F16;&#x8BD1;">2. proto&#x6587;&#x4EF6;&#x7F16;&#x8BD1;</h4>
<h5 id="1&#x7F16;&#x8F91;build&#x6587;&#x4EF6;">1.&#x7F16;&#x8F91;BUILD&#x6587;&#x4EF6;</h5>
<p>&#x5728; demo_base_proto &#x76EE;&#x5F55;&#x4E0B;&#x65B0;&#x5EFA; BUILD &#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x8F93;&#x5165;&#x4EE5;&#x4E0B;&#x5185;&#x5BB9;&#xFF1A;</p>
<pre><code class="lang-py">load(<span class="hljs-string">&quot;//tools:python_rules.bzl&quot;</span>, <span class="hljs-string">&quot;py_proto_library&quot;</span>)
package(default_visibility = [<span class="hljs-string">&quot;//visibility:public&quot;</span>])
proto_library(
    name = <span class="hljs-string">&quot;student_proto&quot;</span>,
    srcs = [<span class="hljs-string">&quot;student.proto&quot;</span>]
)

cc_proto_library(
    name = <span class="hljs-string">&quot;student_cc&quot;</span>,
    deps = [<span class="hljs-string">&quot;:student_proto&quot;</span>]
)

py_proto_library(
    name = <span class="hljs-string">&quot;student_py&quot;</span>,
    deps = [<span class="hljs-string">&quot;:student_proto&quot;</span>]
)
</code></pre>
<p>&#x4EE3;&#x7801;&#x89E3;&#x91CA;&#xFF1A;</p>
<p>1.proto_library &#x51FD;&#x6570;</p>
<p>&#x8BE5;&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x751F;&#x6210; proto &#x6587;&#x4EF6;&#x5BF9;&#x5E94;&#x7684;&#x5E93;&#xFF0C;&#x8BE5;&#x5E93;&#x88AB;&#x5176;&#x4ED6;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x521B;&#x5EFA;&#x4F9D;&#x8D56;&#x5E93;&#x65F6;&#x6240;&#x4F9D;&#x8D56;&#x3002;</p>
<p>&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li>name  &#x76EE;&#x6807;&#x540D;&#x79F0;</li>
<li>srcs  proto&#x6587;&#x4EF6;</li>
</ul>
<p>2.cc_proto_library &#x51FD;&#x6570;</p>
<p>&#x8BE5;&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x751F;&#x6210;C++&#x76F8;&#x5173;&#x7684;proto&#x4F9D;&#x8D56;&#x5E93;&#x3002;</p>
<p>&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li>name &#x76EE;&#x6807;&#x540D;&#x79F0;</li>
<li>deps &#x4F9D;&#x8D56;&#x7684;proto &#x5E93;&#x540D;&#x79F0;</li>
</ul>
<p>3.py_proto_library &#x51FD;&#x6570;</p>
<p>&#x8BE5;&#x51FD;&#x6570;&#x7528;&#x4E8E;&#x751F;&#x6210;Python&#x76F8;&#x5173;&#x7684;proto&#x4F9D;&#x8D56;&#x5E93;&#x3002;</p>
<p>&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li>name &#x76EE;&#x6807;&#x540D;&#x79F0;</li>
<li>deps &#x4F9D;&#x8D56;&#x7684;proto &#x5E93;&#x540D;&#x79F0;</li>
</ul>
<p><strong>&#x6CE8;&#x610F;&#xFF1A;</strong></p>
<ol>
<li>&#x4F7F;&#x7528;py_proto_library &#x5FC5;&#x987B;&#x58F0;&#x660E; load(&quot;//tools:python_rules.bzl&quot;, &quot;py_proto_library&quot;)&#x3002;</li>
<li>proto_library &#x51FD;&#x6570;&#x7684;&#x53C2;&#x6570; name &#x503C;&#x5FC5;&#x987B;&#x540E;&#x7F00; _proto &#x5426;&#x5219;&#xFF0C;python&#x8C03;&#x7528;&#x65F6;&#x4F1A;&#x629B;&#x51FA;&#x5F02;&#x5E38;&#x3002;</li>
<li>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x540E;&#x671F;&#x4F7F;&#x7528;&#xFF0C;&#x5EFA;&#x8BAE;&#x5148;&#x6DFB;&#x52A0;&#x8BED;&#x53E5;&#xFF1A;package(default_visibility = [&quot;//visibility:public&quot;])&#x3002;</li>
</ol>
<h5 id="2&#x7F16;&#x8BD1;">2.&#x7F16;&#x8BD1;</h5>
<p>&#x7EC8;&#x7AEF;&#x4E0B;&#x8FDB;&#x5165; /apollo &#x76EE;&#x5F55;&#xFF0C;&#x6267;&#x884C;&#x7F16;&#x8BD1;&#x547D;&#x4EE4;&#xFF1A;</p>
<pre><code>bazel build cyber/demo_base_proto/...
</code></pre><p>&#x5728; /apollo/bazel-bin/cyber/demo_base_proto &#x4E0B;&#x5C06;&#x751F;&#x6210;&#x53EF;&#x4EE5;&#x88AB;C++&#x548C;Python&#x8C03;&#x7528;&#x7684;&#x4E2D;&#x95F4;&#x6587;&#x4EF6;&#x3002;</p>
<p><img src="../../assets/014_protobuf&#x4E2D;&#x95F4;&#x6587;&#x4EF6;.png" alt=""></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../16-ben-zhang-xiao-jie.html" class="navigation navigation-prev " aria-label="Previous page: 1.6 预备知识——protobuf">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="162-protoshi-yong-zhi-du-xie-cao-zuo.html" class="navigation navigation-next " aria-label="Next page: 1.6.2 proto读写之C++实现">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.6.1 proto使用之文件创建","level":"1.2.6.1","depth":3,"next":{"title":"1.6.2 proto读写之C++实现","level":"1.2.6.2","depth":3,"path":"chapter1/16-ben-zhang-xiao-jie/162-protoshi-yong-zhi-du-xie-cao-zuo.md","ref":"chapter1/16-ben-zhang-xiao-jie/162-protoshi-yong-zhi-du-xie-cao-zuo.md","articles":[]},"previous":{"title":"1.6 预备知识——protobuf","level":"1.2.6","depth":2,"path":"chapter1/16-ben-zhang-xiao-jie.md","ref":"chapter1/16-ben-zhang-xiao-jie.md","articles":[{"title":"1.6.1 proto使用之文件创建","level":"1.2.6.1","depth":3,"path":"chapter1/16-ben-zhang-xiao-jie/161-protoshi-yong-zhi-wen-jian-chuang-jian.md","ref":"chapter1/16-ben-zhang-xiao-jie/161-protoshi-yong-zhi-wen-jian-chuang-jian.md","articles":[]},{"title":"1.6.2 proto读写之C++实现","level":"1.2.6.2","depth":3,"path":"chapter1/16-ben-zhang-xiao-jie/162-protoshi-yong-zhi-du-xie-cao-zuo.md","ref":"chapter1/16-ben-zhang-xiao-jie/162-protoshi-yong-zhi-du-xie-cao-zuo.md","articles":[]},{"title":"1.6.3 proto读写之Python实现","level":"1.2.6.3","depth":3,"path":"chapter1/16-ben-zhang-xiao-jie/163-protodu-xie-zhi-python-shi-xian.md","ref":"chapter1/16-ben-zhang-xiao-jie/163-protodu-xie-zhi-python-shi-xian.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["expandable-chapters"],"pluginsConfig":{"expandable-chapters":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter1/16-ben-zhang-xiao-jie/161-protoshi-yong-zhi-wen-jian-chuang-jian.md","mtime":"2022-04-10T10:26:15.554Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2022-04-10T10:28:55.066Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

